<?php use_helper('crossAppLink') ?>
<?php 
	$q = Doctrine_Query::create()
    ->select('a.id, a.description')
    ->from('menutitle a')
    ->andWhere ('a.backoffice = true')
    ->orderBy('a.xorder')    ;
	$options = $q->execute();
?>

<ul class="sf-menu" id="nav">
  <?php	foreach($options as $menu):?>
	<li><?php echo link_to($menu->description, '@homepage') ?>
		<ul>
			<?php $ssmenu = Doctrine_Query::create()
    			->select('u.name, u.description')
			    ->from('menumodule u')
			    ->andWhere ("u.title_id='". $menu->id."'")
			    ->andWhere ('u.backoffice=1')
			    ->orderBy('u.xorder')    
			    ->execute();
			 ?>
  			<?php	foreach($ssmenu as $sousmenu):?>
  				<?php $params = '';
  					  if($sousmenu->name=='display'){
  						$params = '?className='.$sousmenu->classname;
	  				  }
	  				  if($sousmenu->parameters)
	  				  {
	  				  	if($params=='')
	  				  	{
	  				  		$params = '?' .$sousmenu->parameters; 
	  				  	}
	  				  	else 
	  				  	{
	  				  		$params = '&' .$sousmenu->parameters;
	  				  	}
	  				  }
  				echo '<li>'.link_to($sousmenu->description, $sousmenu->name.'/index'.$params) . '</li>';
  				?>
				
 			 <?php endforeach;?>
 			 
		</ul>
	</li>	
  <?php endforeach;?>
  <li>
  <?php echo link_to(__('Back to main application'), cross_app_link_to('frontend', '@homepage')) ;?>
  </li>
</ul>

  <!-- jQuery with plugins -->
  <script type="text/javascript">
    $(document).ready(function(){
      <!-- initialise sooperfish menu -->
      $('ul.sf-menu').sooperfish({
    	    dualColumn  : 8, //if a submenu has at least this many items it will be divided in 2 columns
    	    tripleColumn  : 10, //if a submenu has at least this many items it will be divided in 3 columns
    	    hoverClass  : 'sfHover',
    	    delay    : 500 //make sure menus only disappear when intended, 500ms is advised by Jacob Nielsen
  	      });
      <!-- goto top javascript -->
      $('.top').click(function() {$('html, body').animate({scrollTop:0}, 'fast'); return false;});
    });
  </script>